package com.leo.weblogdemo.controller;

import com.leo.weblogdemo.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * <p>
 * 测试控制层
 * </p>
 *
 * @author ：Leo
 * @since ：2021-03-10 11:09
 */
@RestController
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);
    private static final String SUCCESS = "success";

    /**
     * POST 方式接口测试
     * @param user 用户信息
     * @return User
     */
    @PostMapping("/user")
    public User testPost(@RequestBody User user) {
        logger.info("testPost ...");
        return user;
    }

    /**
     * GET 方式接口测试
     * @return String
     */
    @GetMapping("/user")
    public String testGet(@RequestParam("username") String username,
                          @RequestParam("password") String password,
                          @RequestParam("createTime")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date createTime) {
        logger.info("testGet ...");
        return SUCCESS;
    }

    /**
     * 单文件上传接口测试
     * @return String
     */
    @PostMapping("/file/upload")
    public String testFileUpload(@RequestParam("file") MultipartFile file) {
        logger.info("testFileUpload ...");
        return SUCCESS;
    }

    /**
     * 多文件上传接口测试
     * @return String
     */
    @PostMapping("/multiFile/upload")
    public String testMultiFileUpload(@RequestParam("file") MultipartFile[] file) {
        logger.info("testMultiFileUpload ...");
        return SUCCESS;
    }
}
